package com.woshua.vptabmodel.tabbar;

import android.animation.ArgbEvaluator;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.woshua.vptabmodel.R;

/**
 * @author Steven.zhao
 * email:hongtu.zhao@goodwinsoft.net
 * date:2019/7/20
 * desc:
 */
public class ItemBar extends FrameLayout {

    private TextView tvBarTitle;
    private ImageView ivBarIcon;
    private ImageView ivBarIconSel;

    private final int DEFAULT_COLOR= Color.BLACK;
    private final int SELECT_COLOR=Color.parseColor("#44C01C");

    public ItemBar(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        final View view = inflate(context, R.layout.layout_bar_item, this);

        initViews(view);
    }

    private void initViews(View view) {
        ivBarIcon=view.findViewById(R.id.iv_icon_bar);
        ivBarIconSel=view.findViewById(R.id.iv_icon_bar_sel);
        tvBarTitle=view.findViewById(R.id.tv_bar_title);
    }

    public void setItemBar(String title,int image,int imageSel)
    {
        tvBarTitle.setText(title);
        ivBarIcon.setImageResource(image);
        ivBarIconSel.setImageResource(imageSel);
    }

    public void setProgress(float progress)
    {
        ivBarIcon.setAlpha(1-progress);
        ivBarIconSel.setAlpha(progress);
        ArgbEvaluator argbEvaluator = new ArgbEvaluator();
        tvBarTitle.setTextColor((int) argbEvaluator.evaluate(progress,DEFAULT_COLOR,SELECT_COLOR));
    }


}
